Repository navigation
optee-utee-sys,optee-teec-sys: generate the FFI bindings instead of maintaining them by hand - #339
Merged
Merged
Conversation
`generate-bindings (utee|teec|all)` runs bindgen against the TA dev kit or the client headers and writes the committed `generated.rs`. `license_header.txt` moves to the repository root so the generator and `optee-utee-build` share it, and `Cargo.lock` is committed so the output stays reproducible.
Replace the hand-written declarations with the bindgen output and the few items bindgen cannot express: the property-set handles, the parameter macros and the entry trampoline. `optee-utee` and `optee-utee-build` follow the generated type names, check the `Option` socket callbacks before calling them, and publish the generated property table. `optee-utee-systest` goes away with the hand-written declarations it checked.
`define_property_key!` now takes a NUL-terminated `&CStr` and prefers the generated `TA_PROP_STR_*` constants, and `AttributeId`, `ObjectStorageConstants`, `MiscellaneousConstants` plus the data, usage and handle flags read their values from `optee-utee-sys`. `ObjectStorageConstants::IllegalValue` keeps its literal: OP-TEE has no macro for it.
Replace the hand-written client declarations with the bindgen output. `optee-teec`, `optee-teec-macros` and `optee-teec-build` follow the generated names and the `Option` callback fields. `optee-teec-systest` goes away with the hand-written declarations it checked, and the documentation that describes the two systest crates is removed.
Add a job that rebuilds the dev kit and the client export from `optee-version.txt`, runs `generate-bindings all`, and fails when the committed `generated.rs` files change. It replaces the ABI coverage that went away with the `*-systest` crates. The release checklist gains the same regeneration step plus the manual property-key pass.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The FFI was maintained by hand in two places, and both had drifted. None of
these mistakes are caught by the compiler or by the tests: they just make a TA
misbehave at run time.
In
optee-utee-sys/optee-teec-sys:match the headers:
TEE_ALG_ECDSA_P192was0x70001041while the header nowaliases it to
TEE_ALG_ECDSA_SHA1(0x70001042), and the same forTEE_ALG_ECDH_P*.In
optee-uteeitself (the safe wrapper), the copied values were wrong too:TaInstanceKeepCrashedusedgpd.ta.instanceKeepCrashed, but the header andthe TA runtime use
optee.ta.instanceKeepCrashed, so the key never matched.TEE_PROPSET_TEE_IMPLEMENTATIONkey set did not match what OP-TEEserves:
gpd.tee.sockets.versionandgpd.tee.sockets.tcp.versionweremissing, while ten keys OP-TEE never implements
(
gpd.tee.cryptography.nist,gpd.tee.trustedStorage.*.rollbackProtection,gpd.tee.event.maxSources, …) were exposed and could only returnTEE_ERROR_ITEM_NOT_FOUND.AttributeIdnamed a constant that does not exist upstream(
RsaOaepMgf1Hash) and lacked the newer ones (TEE_ATTR_BIT_PROTECTED,TEE_ATTR_BIT_VALUE).Fixing these one at a time only moves the problem to the next OP-TEE bump, so
this takes the declarations out of human hands instead: generate them from the
pinned headers, commit the result, and let CI check it.
What this changes
xtaskwithgenerate-bindings (utee|teec|all). It runs bindgenagainst the TA dev kit (
TA_DEV_KIT_DIR) or the client export(
OPTEE_CLIENT_EXPORT) of the release pinned inoptee-version.txt, andrewrites
crates/optee-{utee,teec}-sys/src/generated.rs.OP-TEE headers. Only the few items bindgen cannot express (property-set
handles, parameter macros, the TA entry trampoline) stay hand-written in
handwritten.rs.optee-uteestops carrying literals: the property keys now use the generatedTA_PROP_STR_*constants, and the attribute, storage, usage, data and handleids come from the bindings, so a wrong value can no longer be typed in by
hand. Consumers also follow the generated names and
Optioncallbacks.*-systestcrates are removed. A CI job rebuilds the dev kit and theclient export, re-generates both files and fails on any diff, which replaces
that coverage.
docs/release-tips.mdgains the same step.